﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Web.Routing;

using ProjectBase.Core;

namespace $safeprojectname$
{
    /// <summary>
    /// Decides whether the URL starts with Language or if it is a Controller
    /// </summary>
    public class LangRouteConstraint : IRouteConstraint
    {
        public bool Match(System.Web.HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            return routeDirection.Equals(RouteDirection.UrlGeneration) // true for generating
                || Languages.Contains(values[parameterName]); // routeValues 'parameterName' is like "en-US" 
        }

        #region Languages
        public static readonly IEnumerable<string> Languages = GetLanguages();
        protected static IEnumerable<string> GetLanguages()
        {
            return CultureInfo
                .GetCultures(CultureTypes.AllCultures)
                .Select(l => l.Name);
        }
        #endregion Languages
    }
}
